package com.cloud.code.真题;

import java.util.*;

/**
 * 全排列
 */
public class Demo {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String str = scanner.nextLine();

            char[] chars = str.toCharArray();
            boolean[] used = new boolean[chars.length];
            Set<String> res = new HashSet<>();
            Deque<Character> deque = new ArrayDeque<>();

            dfs(chars, chars.length, 0, used, res, deque);

            System.out.println(res.size());

        }
    }

    private static void dfs(char[] chars, int length, int depth, boolean[] used, Set<String> res, Deque<Character> deque) {

        if (length == depth) {
            String s = Arrays.toString(new Deque[]{deque}).replaceAll("\\W", "");
            res.add(s);
            return;
        }

        for (int i = 0; i < length; i++) {
            if (used[i]) {
                continue;
            }

            used[i] = true;
            deque.addLast(chars[i]);
            dfs(chars, length, depth + 1, used, res, deque);
            deque.removeLast();
            used[i] = false;

        }


    }
}
